<!--
 * @Description: 
 * @Version: 1.0.0
 * @Date: 2022-04-11 10:16:14
-->
<template>
    <div id="captcha" style="height: 0;"></div>
</template>
  
<script setup>
import { defineExpose, defineEmits, computed, ref } from 'vue';

initGeetest4({
    captchaId: "e0ff0f201c666d314840dfd88a2316f8",
    language: "en",
    product: "bind",
}, handler)

const captcha = ref(null)
function handler(captchaObj) {
    captcha.value = captchaObj
    captchaObj
        .appendTo("#captcha")
        .onSuccess(function () {
            validate();
        });
}

const emit = defineEmits(['validate'])

function validate() {
    var result = captcha.value.getValidate();
    if (!result) {
        alert("请先完成验证！");
        return;
    }

    emit('validate', result)
}

defineExpose({
    captcha,
});


</script>